package com.nhjf.dao.tochatwit;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import com.nhjf.dao.BaseDao;
import com.nhjf.model.tochatwith.Tochatwith;
import com.nhjf.pojo.qo.tochatwith.TochatwithQo;

@Repository
public class TochatwitDao extends BaseDao<Tochatwith, TochatwithQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, TochatwithQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null){
			
			if(qo.getTochatwithid()!=null){
				criteria.add(Restrictions.eq("id", qo.getTochatwithid()));
			}
			//发送人
			if(qo.getReceiverId()!=null) {
				criteria.add(Restrictions.eq("receiver", qo.getReceiverId()));
			}
			//接收人
			if(qo.getSenderId()!=null) {
				criteria.add(Restrictions.eq("sender", qo.getSenderId()));
			}
			//发送时间
			if(qo.getSendingtime()!=null) {
				criteria.add(Restrictions.eq("sendingtime", qo.getSendingtime()));
			}
			//发送消息
			if(StringUtils.isNotBlank(qo.getMessage())) {
				criteria.add(Restrictions.eq("message", qo.getMessage()));
			}
			//1未读 2已读
			if(qo.getWhethertoread()!=null) {
				criteria.add(Restrictions.eq("whethertoread", qo.getWhethertoread()));
			}
			//1普通消息 2系统消息
			if(qo.getMessagetype()!=null) {
				criteria.add(Restrictions.eq("messagetype", qo.getMessagetype()));
			}
		}
		return criteria;
	}

	@Override
	protected Class<Tochatwith> getEntityClass() {
		// TODO Auto-generated method stub
		return Tochatwith.class;
	}

	
	
}
